package com.icinfo.cloud.provider.common.zzd.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.provider.common.zzd.service.ILoginService;
import com.icinfo.cloud.provider.punish.dto.LoginRequest;
import com.icinfo.framework.tools.utils.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Service
public class LoginServiceImpl implements ILoginService {
    @Value("${login.url}")
    private String loginUrl;
    /**
     * 用户名密码登录
     * @author liyafeng
     * @date 2022/12/6
      * @param loginRequest
     * @return {@link JSONObject}
     */
    @Override
    public JSONObject login(LoginRequest loginRequest) {
        Map<String,Object> paramMap=new HashMap<>();
        paramMap.put("encParamsStr",loginRequest.getEncParamsStr());
        //String result=HttpUtils.doPostJson(loginUrl,loginJson);
        String result = HttpClientUtil.executeRequest(loginUrl, "POST",
                ContentType.APPLICATION_JSON.getMimeType(), paramMap);
        log.info("登录用户信息:" + result);
        JSONObject resultObjet=JSON.parseObject(result);
        return resultObjet;
    }
}
